package com.splic.web.controller.product;

import java.util.List;
import com.splic.common.utils.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.splic.common.annotation.Log;
import com.splic.common.enums.BusinessType;
import com.splic.product.domain.Province;
import com.splic.product.service.ProvinceService;
import com.splic.common.core.controller.BaseController;
import com.splic.common.core.domain.AjaxResult;
import com.splic.common.utils.poi.ExcelUtil;
import com.splic.common.core.page.TableDataInfo;

/**
 * 省份设置Controller
 * 
 * @author singe
 * @date 2022-03-08
 */
@Controller
@RequestMapping("/product/province")
public class ProvinceController extends BaseController
{
    private String prefix = "product/province";

    @Autowired
    private ProvinceService provinceServiceImpl;

    @RequiresPermissions("product:province:view")
    @GetMapping()
    public String province()
    {
        return prefix + "/list";
    }

    /**
     * 查询省份设置列表
     */
    @RequiresPermissions("product:province:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Province province)
    {
        startPage();
        List<Province> list = provinceServiceImpl.selectProvinceList(province);
        return getDataTable(list);
    }

    /**
     * 新增省份设置
     */
    @GetMapping(value = { "/form/{provinceId}", "/form" })
    public String form(@PathVariable(value = "provinceId", required = false) Long provinceId, ModelMap mmap)
    {
        if (StringUtils.isNotNull(provinceId)){
            mmap.put("province", provinceServiceImpl.selectProvinceByProvinceId(provinceId));
        }else{
            mmap.put("province", new Province());
        }
        return prefix + "/form";
    }


    /**
     * 新增保存省份设置
     */
    @RequiresPermissions("product:province:edit")
    @Log(title = "省份设置", businessType = BusinessType.INSERT)
    @PostMapping("/saveOrUpdate")
    @ResponseBody
    public AjaxResult saveOrUpdate(Province province)
    {
        return toAjax(provinceServiceImpl.saveOrUpdate(province));
    }

    /**
     * 删除
     */
    @RequiresPermissions("product:province:remove")
    @Log(title = "省份设置", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(Long provinceId)
    {
        return toAjax(provinceServiceImpl.deleteById(provinceId));
    }


    /**
     * 导出省份设置列表
     */
    @RequiresPermissions("product:province:export")
    @Log(title = "省份设置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Province province)
    {
        List<Province> list = provinceServiceImpl.selectProvinceList(province);
        ExcelUtil<Province> util = new ExcelUtil<Province>(Province.class);
        return util.exportExcel(list, "省份设置数据");
    }

}
